package cn.stylefeng.guns.modular.myenum;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author 李宝嘉
 * @Date 2022/1/5 14:53
 */
@Getter
public enum PeriodUnitEnum {
    DAY(0, "日"),
    WEEK(1, "周"),
    MONTH(2, "月"),
    YEAR(3, "年");

    PeriodUnitEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @JsonValue
    private final int code;
    @EnumValue
    private final String desc;

    public static PeriodUnitEnum getByCode(int code) {
        for (PeriodUnitEnum p :
                PeriodUnitEnum.values()) {
            if (p.getCode() == code) {
                return p;
            }
        }
        return null;
    }

}
